var status = {
	time: "00:00:00",
	uptime: "0 min",
	loadavg1: 0.00,
	loadavg2: 0.00,
	loadavg3: 0.00,
	algo: "nada"
};

var showtime = document.createElement("span");

function showStatus(status)
{
	showtime.innerHTML=status.loop+" - "+status.time+" | "+status.uptime+" | "+status.loadavg1+", "+status.loadavg2+", "+status.loadavg3;
	var url = "/lua/status.lua?time="+status.time+"&uptime="+status.uptime+"&loadavg1="+status.loadavg1+"&loadavg2="+status.loadavg2+"&loadavg3="+status.loadavg3+"&asdf=99";
	var pepe = new ajaxObject(url, mycallback);
	pepe.update();
};
	
function mycallback(responseText,status,responseXML)
{
	var myObject = eval('(' + responseText + ')');
	status = myObject.status;
	showtime.innerHTML=status.loop+" - "+status.time+" | "+status.uptime+" | "+status.loadavg1+", "+status.loadavg2+", "+status.loadavg3;
//	showStatus(status);
};

function getMenu()
{
	var url = "/lua/menu.lua";
	var pepe = new ajaxObject(url, changeMenu);
	pepe.update();
}

function changeMenu(responseText,status,responseXML)
{
	var oldmenu = document.getElementById("mainmenu");
	var myparent = oldmenu.parentNode;
	var newmenu = document.createElement("div");
//	alert(responseText);
	newmenu.innerHTML = responseText;
	myparent.replaceChild(newmenu,oldmenu);
	
}

function init()
{
	var stdiv = document.getElementById("short-status");
	var maindiv = document.createElement("div");
	var myparent = stdiv.parentNode;
	getMenu();
	maindiv.style.padding = "0 10px 0 0";
	showtime.style.styleFloat = "right";
	showtime.style.cssFloat = "right";
	showtime.style.fontSize = "9px";
	showtime.style.color = "#000";
	showtime.innerHTML="fasdfadf";
	maindiv.appendChild(showtime);
	myparent.replaceChild(maindiv,stdiv);
	showStatus(status);
};
